//
//  ABNetworkUtil.m
//  Hive
//
//  Created by 惠俊贝 on 15/8/20.
//  Copyright (c) 2015年 ZM. All rights reserved.
//
#import "ABNetworkUtil.h"
#import "UserAccount.h"
#import <XMLDictionary.h>
#import "UserDefaultUtil.h"
#import "AreaScope.h"


#ifdef TEST
#define IP              @"http://121.41.123.146:8024/"
#else
#define IP              @"http://f1.hiveset.com/"
#endif

#define CUSTOMER_URL    [NSString stringWithFormat:@"%@customer.asmx",IP]
#define ALERM_URL       [NSString stringWithFormat:@"%@Alarm.asmx",IP]
#define GPS_URL_OLD     @"http://121.41.123.146:8040/gps.asmx"
#define GPS_URL         [NSString stringWithFormat:@"%@gps.asmx",IP]
#define DateLib_URL     [NSString stringWithFormat:@"%@datalib.asmx",IP]
#define RiskService_URL @"http://121.41.123.146:8060/RiskService.asmx"

// Customer MethodNames
#define LOGIN_METHOD_NAME                    @"GetLogin"
#define GET_PARENT_USER_INFO_METHOD_NAME     @"GetParentUserInfo"
#define GET_SELF_USER_EQP_INFO_METHOD_NAME   @"GetSelfUserEqpInfo"
//#define GET_SON_USER_EQP_INFO_METHOD_NAMEL    @"GetSonUserEqpInfo"
#define SET_PWD_METHOD_NAME                  @"SetPwd"

// Alarm MethodNames
#define ADD_AREA_SCOPE_METHOD_NAME           @"AddAreaScope"
#define DEL_AREA_SCOPE_METHOD_NAME           @"DelAreaScope"
#define MODIFY_AREA_SCOPE_METHOD_NAME        @"ModifyAreaScope"
#define QUERY_AREA_SCOPE_METHOD_NAME         @"QueryAreaScope"
#define GET_ALARMS_BY_USERID_ALARMTYPE_METHOD_NAME @"GetAlarmsByUserIDAndAlarmType"

#define GET_ALARMS_BY_USERID_METHOD_NAMEL     @"GetAlarmsByUserID"
#define GET_ALARMS_BY_DEVICEID_ALARMTYPE_METHOD_NAME @"GetAlarmsByDeviceIDAndAlarmType"
#define GET_ALARMS_BY_DEVICEID_METHOD_NAME   @"GetAlarmsByDeviceID"
#define ADD_ALARMS_USRETEL_METHOD_NAME       @"AddAlarmsUserTel"

// GPS MethodNames
#define GET_TRACK_INFO_METHOD_NAME_OLD       @"GetTrackInfoByIMEI"
#define GET_TRACK_INFO_METHOD_NAME           @"GetTrackInfoByDeviceID"
#define RESPONSE_GPS_REPLAY_METHOD_NAME      @"Response_GPS_Replay"

// DATALIB MethodNames
#define QUERY_DATALIB_METHOD_NAME            @"QueryDataLib"

// RiskService MethodNames
#define GET_WEIZHANG_CITYS_METHOD_NAME       @"GetWeizhangCitys"
#define GET_HPZL_METHOD_NAME                 @"GetHpzl"
#define GET_WEIZHANG_METHOD_NAME             @"GetWeizhang"




// Customer Actions
#define LOGIN_ACTION_URL                    @"http://tempuri.org/GetLogin"
#define GET_PARENT_USER_INFO_ACTION_URL     @"http://tempuri.org/GetParentUserInfo"
#define GET_SELF_USER_EQP_INFO_ACTION_URL   @"http://tempuri.org/GetSelfUserEqpInfo"
//#define GET_SON_USER_EQP_INFO_ACTION_URL    @"http://tempuri.org/GetSonUserEqpInfo"
#define SET_PWD_ACTION_URL                  @"http://tempuri.org/SetPwd"

// Alarm Actions
#define ADD_AREA_SCOPE_ACTION_URL           @"http://tempuri.org/AddAreaScope"
#define DEL_AREA_SCOPE_ACTION_URL           @"http://tempuri.org/DelAreaScope"
#define MODIFY_AREA_SCOPE_ACTION_URL        @"http://tempuri.org/ModifyAreaScope"
#define QUERY_AREA_SCOPE_ACTION_URL         @"http://tempuri.org/QueryAreaScope"
#define GET_ALARMS_BY_USERID_ALARMTYPE_ACTION_URL @"http://tempuri.org/GetAlarmsByUserIDAndAlarmType"

#define GET_ALARMS_BY_USERID_ACTION_URL     @"http://tempuri.org/GetAlarmsByUserID"
#define GET_ALARMS_BY_DEVICEID_ALARMTYPE_ACTION_URL @"http://tempuri.org/GetAlarmsByDeviceIDAndAlarmType"
#define GET_ALARMS_BY_DEVICEID_ACTION_URL   @"http://tempuri.org/GetAlarmsByDeviceID"
#define ADD_ALARMS_USRETEL_ACTION_URL       @"http://tempuri.org/AddAlarmsUserTel"

// GPS Actions
#define GET_TRACK_INFO_ACTION_URL_OLD       @"http://tempuri.org/GetTrackInfoByIMEI"
#define GET_TRACK_INFO_ACTION_URL           @"http://tempuri.org/GetTrackInfoByDeviceID"
#define RESPONSE_GPS_REPLAY_ACTION_URL      @"http://tempuri.org/Response_GPS_Replay"

// DATALIB Actions
#define QUERY_DATALIB_ACTION_URL            @"http://tempuri.org/QueryDataLib"

// RiskService Actions
#define GET_WEIZHANG_CITYS_ACTION_URL       @"http://tempuri.org/GetWeizhangCitys"
#define GET_HPZL_ACTION_URL                 @"http://tempuri.org/GetHpzl"
#define GET_WEIZHANG_ACTION_URL             @"http://tempuri.org/GetWeizhang"

//???://TimeFormat=yyyy-MM-dd HH:mm:ss




@implementation NSDictionary (SoapResponse)

- (NSDictionary *)soapResponseDictionaryWithMethodName:(NSString *)methodName {
    NSString *secondKey = [NSString stringWithFormat:@"%@Response",methodName];
    NSString *thirdKey = [NSString stringWithFormat:@"%@Result",methodName];
    return [[[self objectForKey:@"soap:Body"]
      objectForKey:secondKey]
     objectForKey:thirdKey];
}

@end


@interface ABNetworkUtil () {
    
}

@end

@implementation ABNetworkUtil

- (id)init {
  self = [super init];
  if (self) {

  }
  return self;
}

- (void)loginWithUserAccount:(UserAccount *)user
                     success:(ABNetworkSuccessBlock)success
                        fail:(ABNetworkFailBlock)fail;
{
    NSDictionary *dic = @{@"User":[user encodeToDictionary]};

    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"customer"];
    NSString *postData = [soaputility BuildSoapwithMethodName:LOGIN_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = CUSTOMER_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:LOGIN_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:LOGIN_METHOD_NAME];
                               
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//  [soap setValue:user forKey:@"User"];
//  [soap requestURL:CUSTOMER_URL
//      soapAction:LOGIN_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)getParentUserInfoWithToken:(NSString *)token
                           success:(ABNetworkSuccessBlock)success
                              fail:(ABNetworkFailBlock)fail {
    
    NSDictionary *dic = @{@"TokenString":token};

    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"customer"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_PARENT_USER_INFO_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = CUSTOMER_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_PARENT_USER_INFO_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_PARENT_USER_INFO_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:CUSTOMER_URL
//      soapAction:GET_PARENT_USER_INFO_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//          
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)getSelfUserEqpInfoWithToken:(NSString *)token
                            success:(ABNetworkSuccessBlock)success
                               fail:(ABNetworkFailBlock)fail {
    
    NSDictionary *dic = @{@"TokenString":token,
                          @"page":@"1",
                          @"pageSize":@"100"};
    
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"customer"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_SELF_USER_EQP_INFO_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = CUSTOMER_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_SELF_USER_EQP_INFO_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_SELF_USER_EQP_INFO_METHOD_NAME];

        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
    
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:CUSTOMER_URL
//      soapAction:GET_SELF_USER_EQP_INFO_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

//- (void)getSonUserEqpInfoWithSonUserId:(NSString *)sonUserId
//                             withToken:(NSString *)token
//                               success:(ABNetworkSuccessBlock)success
//                                  fail:(ABNetworkFailBlock)fail {
//  [soap setValue:sonUserId forKey:@"SonUserID"];
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:CUSTOMER_URL
//      soapAction:GET_SON_USER_EQP_INFO_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
//}

- (void)setPasswordWithOldPWD:(NSString *)oldPWD
                   withNewPWD:(NSString *)newPWD
                    withToken:(NSString *)token
                      success:(ABNetworkSuccessBlock)success
                         fail:(ABNetworkFailBlock)fail {

    NSDictionary *dic = @{@"oldPwd":oldPWD,
                          @"newPwd":newPWD,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"customer"];
    NSString *postData = [soaputility BuildSoapwithMethodName:SET_PWD_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = CUSTOMER_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:SET_PWD_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:SET_PWD_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
//  [soap setValue:oldPWD forKey:@"oldPwd"];
//  [soap setValue:newPWD forKey:@"newPwd"];
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:CUSTOMER_URL
//      soapAction:SET_PWD_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

// GPS
- (void)getTrackInfoByIMEI:(NSString *)IMEI
                   success:(ABNetworkSuccessBlock)success
                      fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"IMEI":IMEI,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"gps"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_TRACK_INFO_METHOD_NAME_OLD withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = GPS_URL_OLD;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_TRACK_INFO_METHOD_NAME_OLD SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_TRACK_INFO_METHOD_NAME_OLD];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//    [soap setValue:IMEI forKey:@"IMEI"];
//    [soap setValue:token forKey:@"TokenString"];
//    [soap requestURL:GPS_URL_OLD
//          soapAction:GET_TRACK_INFO_ACTION_URL_OLD
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}


- (void)getTrackInfoByDeviceID:(NSString *)DeviceID
                   success:(ABNetworkSuccessBlock)success
                      fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"Device":DeviceID,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"gps"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_TRACK_INFO_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = GPS_URL_OLD;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_TRACK_INFO_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_TRACK_INFO_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//  NSString *token = TOKEN;
//  [soap setValue:DeviceID forKey:@"DeviceID"];
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:GPS_URL
//      soapAction:GET_TRACK_INFO_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)getResponseGPSReplyWithDeviceID:(NSString *)deviceId
                          startTime:(NSString *)startTime
                            endTime:(NSString *)endTime
                            success:(ABNetworkSuccessBlock)success
                               fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"DeviceID":deviceId,
                          @"StartTime":startTime,
                          @"EndTime":endTime,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"gps"];
    NSString *postData = [soaputility BuildSoapwithMethodName:RESPONSE_GPS_REPLAY_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = GPS_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:RESPONSE_GPS_REPLAY_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:RESPONSE_GPS_REPLAY_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
//  NSString *token = TOKEN;
//  [soap setValue:deviceId forKey:@"DeviceID"];
//  [soap setValue:startTime forKey:@"StartTime"];
//  [soap setValue:endTime forKey:@"EndTime"];
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:GPS_URL
//      soapAction:RESPONSE_GPS_REPLAY_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

// Alarm
- (void)addAreaScope:(AreaScope *)areaScope
             success:(ABNetworkSuccessBlock)success
                fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"areaScope":@{@"ID":areaScope.ID,
                                         @"AreaName":areaScope.AreaName,
                                         @"UserID":areaScope.UserID,
                                         @"AreaType":areaScope.AreaType,
                                         @"ParameterSets":areaScope.ParameterSets,
                                         @"State":[[NSNumber numberWithBool:areaScope.State] stringValue],
                                         @"Remark":areaScope.Remark,
                                         @"InOrOut":[[NSNumber numberWithBool:areaScope.InOrOut] stringValue],
                                         @"DeviceID":areaScope.DeviceID,
                                  },
                          @"tokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:ADD_AREA_SCOPE_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:ADD_AREA_SCOPE_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:ADD_AREA_SCOPE_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//    
//  NSString *token = TOKEN;
//  [soap setValue:areaScope forKey:@"areaScope"];
//  [soap setValue:token forKey:@"tokenString"];
//  [soap requestURL:ALERM_URL
//      soapAction:ADD_AREA_SCOPE_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)delAreaScope:(AreaScope *)areaScope
             success:(ABNetworkSuccessBlock)success
                fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"areaScope":@{@"ID":areaScope.ID,
                                         @"AreaName":areaScope.AreaName,
                                         @"UserID":areaScope.UserID,
                                         @"AreaType":areaScope.AreaType,
                                         @"ParameterSets":areaScope.ParameterSets,
                                         @"State":[[NSNumber numberWithBool:areaScope.State] stringValue],
                                         @"Remark":areaScope.Remark,
                                         @"InOrOut":[[NSNumber numberWithBool:areaScope.InOrOut] stringValue],
                                         @"DeviceID":areaScope.DeviceID,
                                         },
                          @"tokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:DEL_AREA_SCOPE_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:DEL_AREA_SCOPE_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:DEL_AREA_SCOPE_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];

    
    
//  NSString *token = TOKEN;
//  [soap setValue:areaScope forKey:@"areaScope"];
//  [soap setValue:token forKey:@"tokenString"];
//  [soap requestURL:ALERM_URL
//      soapAction:DEL_AREA_SCOPE_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)modifyAreaScope:(AreaScope *)areaScope
                success:(ABNetworkSuccessBlock)success
                   fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"areaScope":@{@"ID":areaScope.ID,
                                         @"AreaName":areaScope.AreaName,
                                         @"UserID":areaScope.UserID,
                                         @"AreaType":areaScope.AreaType,
                                         @"ParameterSets":areaScope.ParameterSets,
                                         @"State":[[NSNumber numberWithBool:areaScope.State] stringValue],
                                         @"Remark":areaScope.Remark,
                                         @"InOrOut":[[NSNumber numberWithBool:areaScope.InOrOut] stringValue],
                                         @"DeviceID":areaScope.DeviceID,
                                         },
                          @"tokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:MODIFY_AREA_SCOPE_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:MODIFY_AREA_SCOPE_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:MODIFY_AREA_SCOPE_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
//  NSString *token = TOKEN;
//  [soap setValue:areaScope forKey:@"areaScope"];
//  [soap setValue:token forKey:@"tokenString"];
//  [soap requestURL:ALERM_URL
//      soapAction:MODIFY_AREA_SCOPE_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)queryAreaScopeWithDeviceID:(NSString *)deviceId
                           success:(ABNetworkSuccessBlock)success
                              fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"deviceID":deviceId,
                          @"tokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:QUERY_AREA_SCOPE_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:QUERY_AREA_SCOPE_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:QUERY_AREA_SCOPE_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
//  NSString *token = TOKEN;
//  [soap setValue:deviceId forKey:@"deviceID"];
//  [soap setValue:token forKey:@"tokenString"];
//  [soap requestURL:ALERM_URL
//      soapAction:QUERY_AREA_SCOPE_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)getAlarmsByUserID:(NSString *)userID
             andAlarmType:(NSString *)alarmType
                startTime:(NSString *)startTime
                  endTime:(NSString *)endTime
                  success:(ABNetworkSuccessBlock)success
                     fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"UserID":userID,
                          @"AlarmType":alarmType,
                          @"StartTime":startTime,
                          @"EndTime":endTime,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_ALARMS_BY_USERID_ALARMTYPE_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_ALARMS_BY_USERID_ALARMTYPE_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_ALARMS_BY_USERID_ALARMTYPE_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//  NSString *token = TOKEN;
//  [soap setValue:userID forKey:@"UserID"];
//  [soap setValue:startTime forKey:@"StartTime"];
//  [soap setValue:endTime forKey:@"EndTime"];
//  [soap setValue:alarmType forKey:@"AlarmType"];
//  [soap setValue:token forKey:@"TokenString"];
//  [soap requestURL:ALERM_URL
//      soapAction:GET_ALARMS_BY_USERID_ALARMTYPE_ACTION_URL
//      completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//        success(dict);
//      }
//      failWithError:^(NSError *error) {
//        fail(error);
//      }];
}

- (void)getAlarmsByUserID:(NSString *)userID
                startTime:(NSString *)startTime
                  endTime:(NSString *)endTime
                  success:(ABNetworkSuccessBlock)success
                     fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"UserID":userID,
                          @"StartTime":startTime,
                          @"EndTime":endTime,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_ALARMS_BY_USERID_METHOD_NAMEL withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_ALARMS_BY_USERID_METHOD_NAMEL SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_ALARMS_BY_USERID_METHOD_NAMEL];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//    NSString *token = TOKEN;
//    NSDictionary *queryAlarms = @{
//                                  @"UserID":userID,
//                                  @"StartTime":startTime,
//                                  @"EndTime":endTime
//                                  };
////    [soap setValue:userID forKey:@"UserID"];
////    [soap setValue:startTime forKey:@"StartTime"];
////    [soap setValue:endTime forKey:@"EndTime"];
//    [soap setValue:queryAlarms forKey:@"queryAlarms"];
//    [soap setValue:token forKey:@"TokenString"];
//    [soap requestURL:ALERM_URL
//          soapAction:GET_ALARMS_BY_USERID_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

- (void)getAlarmsByDeviceID:(NSString *)deviceID
               andAlarmType:(NSString *)alarmType
                  startTime:(NSString *)startTime
                    endTime:(NSString *)endTime
                    success:(ABNetworkSuccessBlock)success
                     fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"DeviceID":deviceID,
                          @"AlarmType":alarmType,
                          @"StartTime":startTime,
                          @"EndTime":endTime,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_ALARMS_BY_DEVICEID_ALARMTYPE_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_ALARMS_BY_DEVICEID_ALARMTYPE_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_ALARMS_BY_DEVICEID_ALARMTYPE_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
//    NSString *token = TOKEN;
//    [soap setValue:deviceID forKey:@"DeviceID"];
//    [soap setValue:startTime forKey:@"StartTime"];
//    [soap setValue:endTime forKey:@"EndTime"];
//    [soap setValue:alarmType forKey:@"AlarmType"];
//    [soap setValue:token forKey:@"TokenString"];
//    [soap requestURL:ALERM_URL
//          soapAction:GET_ALARMS_BY_DEVICEID_ALARMTYPE_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

- (void)getAlarmsByDeviceID:(NSString *)deviceID
                  startTime:(NSString *)startTime
                    endTime:(NSString *)endTime
                    success:(ABNetworkSuccessBlock)success
                       fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"DeviceID":deviceID,
                          @"StartTime":startTime,
                          @"EndTime":endTime,
                          @"TokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_ALARMS_BY_DEVICEID_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_ALARMS_BY_DEVICEID_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_ALARMS_BY_DEVICEID_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
//    NSString *token = TOKEN;
//    [soap setValue:deviceID forKey:@"DeviceID"];
//    [soap setValue:startTime forKey:@"StartTime"];
//    [soap setValue:endTime forKey:@"EndTime"];
//    [soap setValue:token forKey:@"TokenString"];
//    [soap requestURL:ALERM_URL
//          soapAction:GET_ALARMS_BY_DEVICEID_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

- (void)addAlarmsUserTel:(NSString *)deviceID
                 telList:(NSArray *)telList
             success:(ABNetworkSuccessBlock)success
                fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"deviceID":deviceID,
                          @"telList":telList,
                          @"tokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"Alarm"];
    NSString *postData = [soaputility BuildSoapwithMethodName:ADD_ALARMS_USRETEL_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = ALERM_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:ADD_ALARMS_USRETEL_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:ADD_ALARMS_USRETEL_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
    
//    NSString *token = TOKEN;
//    [soap setValue:deviceID forKey:@"deviceID"];
//    [soap setValue:telList forKey:@"telList"];
//    [soap setValue:token forKey:@"tokenString"];
//    [soap requestURL:ALERM_URL
//          soapAction:ADD_AREA_SCOPE_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

// DataLib
- (void)queryDataLib:(NSString *)dataType
             success:(ABNetworkSuccessBlock)success
                fail:(ABNetworkFailBlock)fail {
    
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"dataType":dataType,
                          @"tokenString":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"datalib"];
    NSString *postData = [soaputility BuildSoapwithMethodName:QUERY_DATALIB_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = DateLib_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:QUERY_DATALIB_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:QUERY_DATALIB_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];

//    NSString *token = TOKEN;
//    [soap setValue:dataType forKey:@"dataType"];
//    [soap setValue:token forKey:@"tokenString"];
//    [soap requestURL:DateLib_URL
//          soapAction:QUERY_DATALIB_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}


// RiskService
- (void)getWeiZhangCitysuccess:(ABNetworkSuccessBlock)success
                       fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"token":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"RiskService"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_WEIZHANG_CITYS_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = RiskService_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_WEIZHANG_CITYS_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_WEIZHANG_CITYS_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//    NSString *token = TOKEN;
//    [soap setValue:token forKey:@"token"];
//    [soap requestURL:RiskService_URL
//          soapAction:GET_WEIZHANG_CITYS_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

- (void)getHplzsuccess:(ABNetworkSuccessBlock)success
                  fail:(ABNetworkFailBlock)fail {
    
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"token":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"RiskService"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_WEIZHANG_CITYS_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = RiskService_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_WEIZHANG_CITYS_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_WEIZHANG_CITYS_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//    NSString *token = TOKEN;
//    [soap setValue:token forKey:@"token"];
//    [soap requestURL:RiskService_URL
//          soapAction:GET_HPZL_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

- (void)getWeizhangCity:(NSString *)city
                   hphm:(NSString *)hphm
                   hpzl:(NSString *)hpzl
               engineno:(NSString *)engineno
                classno:(NSString *)classno
               registno:(NSString *)registno
                success:(ABNetworkSuccessBlock)success
                   fail:(ABNetworkFailBlock)fail {
    NSString *token = [UserDefaultUtil getToken];
    
    NSDictionary *dic = @{@"city":city,
                          @"hphm":hphm,
                          @"hpzl":hpzl,
                          @"engineno":engineno,
                          @"classno":classno,
                          @"registno":registno,
                          @"token":token};
    
    SoapUtility *soaputility = [[SoapUtility alloc] initFromFile:@"RiskService"];
    NSString *postData = [soaputility BuildSoapwithMethodName:GET_WEIZHANG_METHOD_NAME withParas:dic];
    
    SoapService *soaprequest = [[SoapService alloc] init];
    soaprequest.PostUrl = RiskService_URL;
    soaprequest.SoapAction = [soaputility GetSoapActionByMethodName:GET_WEIZHANG_METHOD_NAME SoapType:SOAP];
    
    [soaprequest PostAsync:postData Success:^(NSString *response) {
        NSDictionary *dic = [[NSDictionary dictionaryWithXMLString:response] soapResponseDictionaryWithMethodName:GET_WEIZHANG_METHOD_NAME];
        
        success(dic);
    } falure:^(NSError *response) {
        fail(response);
    }];
    
//    NSString *token = TOKEN;
//    [soap setValue:city forKey:@"city"];
//    [soap setValue:hphm forKey:@"hphm"];
//    [soap setValue:engineno forKey:@"engineno"];
//    [soap setValue:classno forKey:@"classno"];
//    [soap setValue:registno forKey:@"registno"];
//    [soap setValue:token forKey:@"token"];
//    [soap requestURL:RiskService_URL
//          soapAction:GET_WEIZHANG_ACTION_URL
//completeWithDictionary:^(NSInteger statusCode, NSDictionary *dict) {
//    success(dict);
//}
//       failWithError:^(NSError *error) {
//           fail(error);
//       }];
}

@end


